function Swiper (id, obj) {
  this.num = 0;
  this.obj = obj;
  this.banner = document.getElementById(id); //整个banner最大的外套
  this.divs = this.banner.querySelectorAll(".slide_wrap>div");//所有切换的div
  this.lis = this.banner.querySelectorAll(".banner_nav li");//所有的小圆点
  this.prve = this.banner.querySelector(".prev");//前按钮
  this.next = this.banner.querySelector(".next");//后按钮
  this.timer = null; //整个轮播图的定时器
  this.lunbo();//调用自动轮播
  this.stopBanner();//鼠标移入移除
  if (this.obj.banner_nav) {
    this.navClick();//圆点绑定点击事件
  }
  if (this.obj.banner_ctrl) {
    this.ctrlClick();//初始前后按钮
  }
}

// 自动轮播 lunbo 
Swiper.prototype.lunbo = function () {
  // var that = this;
  this.timer = setInterval(() => {
    this.move()
  }, this.obj.interval)
}
//鼠标移入移除轮播的方法
Swiper.prototype.stopBanner = function () {
  var that = this;
  this.banner.onmouseover = function () {
    clearInterval(that.timer)
  }
  this.banner.onmouseout = function () {
    that.timer = setInterval(() => {
      that.move()
    }, that.obj.interval)
  }
}
// 前后按钮点击事件 
Swiper.prototype.ctrlClick = function () {
  var that = this;
  // 前按钮点击
  this.prve.onclick = function () {
    that.num--;
    if (that.num < 0) {
      that.num = that.divs.length - 1;
    }
    that.change();
  }
  // 后按钮点击
  this.next.onclick = function () {
    that.move()
  }
}
// 小圆点 点击事件
Swiper.prototype.navClick = function () {
  var that = this;
  for (let i = 0; i < this.lis.length; i++) {
    this.lis[i].onclick = function () {
      that.num = i;
      that.change()
    }
  }
}
// 轮播图滚动函数move 下标++ 
Swiper.prototype.move = function () {
  this.num++;//下标++
  if (this.num > this.divs.length - 1) {
    this.num = 0;
  }
  this.change()//下标++后调用change函数改变
}

// 改变轮播图函数change 
Swiper.prototype.change = function () {
  for (var i = 0; i < this.divs.length; i++) {
    // 隐藏所有的显示div
    this.divs[i].style.display = "none";
    //所有的li 都移除active的class
    this.lis[i].className = ""
  }
  this.divs[this.num].style.display = "block"//对应下标的div显示、
  this.lis[this.num].className = "active";//对应下标的li加上active的class
}

